import request from "./request"
export function getCategories(type,pagenum,pagesize){
  return request({
    url:'/categories',
    method: 'GET',
    params:{
      type:type,
      pagenum:pagenum,
      pagesize:pagesize
    }
  })
}
export function addCategory(cat_name,cat_level,cat_pid){
  return request({
    url:'/categories',
    method:'post',
    data:{
      cat_level,
      cat_name,
      cat_pid
    }
  })
}
export function deleteCategory(id){
  return request({
    url:`/categories/${id}`,
    method:"delete"
  })
}
export function editCategory(id,cat_name){
  return request({
    url:`/categories/${id}`,
    method:'PUT',
    data:{
      cat_name
    }
  })
}

export function getGoods(parameters){
  return request({
    url:'/goods',
    method: 'get',
    params:parameters
  })
}

export function deleteGood(id){
  return request({
    url:`/goods/${id}`,
    method:'DELETE'
  })
}

export function getGoodsInfoById(id){
  return request({
    url:`/goods/${id}`,
    method:"GET"
  })
}
export function editGoodById(id,data){
  return request({
    url:`goods/${id}`,
    method:'PUT',
    data
  })
}

export function getAttributesById(id,sel){
  return request({
    url:`/categories/${id}/attributes`,
    method:"GET",
    params:{
      sel:sel
    }
  })
}
export function addAttrById(id,attr_name,attr_sel,attr_vals){
  return request({
    url:`/categories/${id}/attributes`,
    method:'POST',
    data:{
      attr_name:attr_name,
      attr_sel:attr_sel,
      attr_vals:attr_vals,
    }
  })
}
export function deleteAttrById(id,attrId){
  return request({
    url: `/categories/${id}/attributes/${attrId}`,
    method: 'delete'
  })
}

export function addGood(data){
  return request({
    url:`/goods`,
    method: 'POST',
    data
  })
}